<template>
  <div class="page" >
    <headerbar>选择类型</headerbar>

    <div class="frame-content-sub bg-default">

      <section class="people-list ">
        <div :class="{'active-select':isSelected(item)}" @click="select(item)" v-for="item in list" class="people-item block noborder">
          <section class="people-info">
            <span class="name">{{item.name}}</span>
          </section>
          <span class=""><span :class="{'icon-radio-checked':isSelected(item)}" class="icon-radio"></span></span>
        </div>

        <p class="pdv-9"></p>
        <p class="pdv-9"></p>
      </section>

      <div class="default-block-btn mgh-5" @click="save">确定</div>


    </div>
  </div>
</template>

<script>
  import footerbar from '../common/footerbar.vue'
  import tools from '@/utils/tools'
  import loginService from '@/service/loginService'
  import scheduleSign from '@/components/work/schedule/scheduleSign'
  import _ from 'lodash'
  export default {
    components: {
      footerbar, scheduleSign
    },
    name: '',
    data () {
      return {
        fn: tools,
        tabIndex: 0,
        userInfo: this.$store.state.userInfo,
        list: [],
        scheduleTypeSelected: {},
        specialType: {},
        selectedList: []
      }
    },
    created () {
      this.loadData()
    },
    methods: {
      isSelected (item) {
        return this.selectedIndexOf(item) > -1
      },
      select (item) {
        // 如果第一个是 主题党日室外，选择的项目不是此项，就重置已选列表
        if (this.selectedList.length > 0 && this.selectedList[0].name === this.specialType.name && this.specialType.name !== item.name) {
          this.selectedList = []
        }
        let index = this.selectedIndexOf(item)
        if (index >= 0) {
          this.selectedList.splice(index, 1)
        } else {
          if (item.name === this.specialType.name) {
            this.selectedList = []
          }
          this.selectedList.push(item)
        }
      },
      selectedIndexOf (item) {
        let index = -1
        this.selectedList.some((v, i) => {
          if (item.name === v.name) {
            index = i
            return false
          }
        })
        return index
      },
      // 会议类型
      appGetMeetingType () {
        // loginService.appGetMeetingType().then((res) => {
        //   if (res.code === 200) {
        //     let list = res.data
        //     let destIndex = 0
        //     list.map((v, i) => {
        //       if (v.name === '主题党日') {
        //         destIndex = i
        //         this.specialType = _.extend({}, v)
        //         this.specialType.name += '(室外)'
        //         v.name += '(室内)'
        //       }
        //       return v
        //     })
        //     list.splice(destIndex + 1, 0, this.specialType)
        //     this.$store.state.scheduleTypes = this.list = list
        //   }
        // })
        let shyk = {
          value: 'shyk',
          name: '三会一课'
        }
        let ztdr = {
          value: 'ztdr',
          name: '主题党日'
        }
        let mzpy = {
          value: 'mzpy',
          name: '民主评议'
        }
        this.list.push(shyk)
        this.list.push(ztdr)
        this.list.push(mzpy)
      },
      save () {
        this.$store.state.scheduleTypeSelected = this.selectedList
        tools.back()
      },
      loadData () {
        if (Array.isArray(this.$store.state.scheduleTypeSelected)) {
          this.selectedList = this.$store.state.scheduleTypeSelected || []
        }
        this.appGetMeetingType()
      }
    }
  }
</script>
